﻿function moneyrange(value, element, param) {
    return Number(value) % Number(param) == 0 && Number(value) > 0;
}

jQuery.validator.addMethod("moneyrange", moneyrange, "借款金额必须是100的倍数.");

jQuery.validator.unobtrusive.adapters.addSingleVal('moneyrange', 'rangevalue');

var dialogOptions = { modal: true, autoOpen: false, draggable: false, position: ["center", "center"], width: '600', height: '300' };

function AddressJoin(provincialID, cityID, areaID, addressName) {
    var provinceName;
    var citys;
    for (var provinceIndex in provinces) {
        if (provinces[provinceIndex].number == provincialID) {
            provinceName = provinces[provinceIndex].name;
            citys = provinces[provinceIndex].citys;
            break;
        }
    }

    var cityname;
    var areas;
    if (citys) {
        for (var cityIndex in citys) {
            if (citys[cityIndex].number == cityID) {
                cityname = citys[cityIndex].name;
                areas = citys[cityIndex].areas;
                break;
            }
        }
    }

    var areaName;
    if (areas) {
        for (var areaIndex in areas) {
            if (areas[areaIndex].number == areaID) {
                areaName = areas[areaIndex].name;
                break;
            }
        }
    }

    return cityname;
}

$(document).ready(function () {

    var accountAddressInfoTd = $('#accountInfoAddress');
    var accountAddressInfoProvincialID = $('#account_AccountInfo_ProvincialID');
    var accountAddressInfoCountyID = $('#account_AccountInfo_CountyID');
    var accountAddressInfoCityID = $('#account_AccountInfo_CityID');
    var accountAddressInfoAreaName = $('#account_AccountInfo_AreaName');
    if (accountAddressInfoProvincialID && accountAddressInfoCountyID && accountAddressInfoCityID && accountAddressInfoAreaName) {
        var str = AddressJoin(accountAddressInfoProvincialID.val(), accountAddressInfoCountyID.val(), accountAddressInfoCityID.val(), accountAddressInfoAreaName.val());
        accountAddressInfoTd.text(str);
        accountAddressInfoTd.attr('title', str);
    }

    $('#ModelSubmitBtn').click(function () {
        $('form').submit();
    });


    $('#puting').click(function () {

        if ($('#IsLogin').val() == "True") {
            if ($('form').valid()) {
                $('#putMoeny').html($('#LendMoney').val() + "元");
                //$('#putDialog').dialog('open');
                $('#ConfirmDialog').modal('toggle');
            }
        }
        else
        {
            window.location = "/Login/SignIn?rawurl=" + encodeURI("/Lenders/LendrsDetail?id=" + $("#Id").val());
        }


        //    if (!$(this).valid()) {
        //        return false;
        //    }
        //    else {
        //        $('#putDialog').dialog(dialogOptions).show();
        //    }
        //});
    });
});